<?php

namespace Modules\Goods\Entities;

use Illuminate\Database\Eloquent\Model;

class Shop extends Model
{
    protected $guarded = [];


    public static function gettopAttrs($gid){
        //获取gid对应的当前商品的可用属性数据对应的id
        $keyongid = Goods::where('id',$gid)->pluck('attrs');
//        dump($keyongid->toArray());
//        打印后为字符串
        //把获取到的当前商品的可用属性对应的id数据转化为数组
        $keyongAttrs = explode(',',$keyongid[0]);
//        dd($keyongAttrs);
        //然后获取当前商品可用属性的所有顶级属性
        $topAttrs = Attr::whereIn('id',$keyongAttrs)->get();
//        dd($topAttrs->toArray());
        //然后找到所有顶级属性的子属性
        foreach ($topAttrs as $k=>$v){
            $topAttrs[$k]['son'] = Attr::where('pid',$v['id'])->get();
        }
        return $topAttrs;
    }
}


